﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NLUNZ
{
    public partial class Default : System.Web.UI.Page
    {
        public CompanyInfo LatestNews { get; set; }
        public List<CompanyInfo> NewsList { get; set; }
        public List<Partner> Partners { get; set; } 

        protected void Page_Load(object sender, EventArgs e)
        {
            LoadNews();
            LoadPartner();
        }

        private void LoadPartner()
        {
            Partners = Repository.GetAllPartners();
        }

        private void LoadNews()
        {
            List<CompanyInfo> latestNews = Repository.GetLatestNews(6);
            if(latestNews.Count > 0)
            {
                //get the top 1 news
                LatestNews = latestNews[0];
                
                if(latestNews.Count > 1)
                {
                    NewsList = latestNews.Skip(1).ToList();
                }
            }
        }
        
        protected void RadTextBoxTracking_TextChanged(object sender, EventArgs e)
        {
            SearchTracking();
        }

        private void SearchTracking()
        {
            string keys = RadTextBoxTracking.Text;
            Response.Redirect("~/Tracking.aspx?keys=" + keys);
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            SearchTracking();
        }
    }
}